package com.thinklib.mapper;

import com.thinklib.bean.Book;
import com.thinklib.bean.ExtCode;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import java.util.List;

public interface SearchMapper {

    // 首页搜索功能：根据书名模糊搜索
    //@Select("SELECT * FROM t_book WHERE book_name LIKE CONCAT('%',#{book_name},'%')")
    @Select("SELECT book_id,book_name,avatar,alibaba_cloud,baidu_cloud,update_time FROM t_book WHERE POSITION(#{book_name} IN `book_name`)")
    @Results({
            @Result(column = "book_id", property = "bookId"),
            @Result(column = "book_name", property = "bookName"),
            @Result(column = "avatar", property = "avatar"),
            @Result(column = "alibaba_cloud", property = "alibabaCloud"),
            @Result(column = "baidu_cloud", property = "baiduCloud"),
            @Result(column = "update_time", property = "updateTime")
    })
    List<Book> search(String bookName);

    // 获取提取码
    @Select("SELECT alibaba_cloud_ext_code,baidu_cloud_ext_code FROM t_ext_code WHERE book_id = #{bookId}")
    @Results({
            @Result(column = "alibaba_cloud_ext_code", property = "alibabaCloudExtCode"),
            @Result(column = "baidu_cloud_ext_code", property = "baiduCloudExtCode")
    })
    ExtCode findExtCodeByBookId(int bookId);

}
